from pylons import request

from chowa.lib.helpers import *
from pylons import url
from webhelpers.html.builder import HTML

def division_link(division, **kwargs):
    return link_to(unicode(division), url=url.current(action='division', id=division.id), **kwargs)

def tag_link(tag, **kwargs):
    return link_to(unicode(tag), url(controller='docs', action='tag', id=tag.id), **kwargs)

def file_link(file, **kwargs):
    return link_to(file, url(controller='document', action='file', id=file.id), **kwargs)

def favor_url(doc_id):
    _func = 'change_favorite_status'
    _url = url(controller='document', action='favorite', id=doc_id)
    return "javascript:%s('%s', 'favor-status-%s')" % (_func, _url, doc_id)
    

def favor_class(doc):
    try:
        user = request.environ.get('repoze.who.identity')['user']
        return 'favor' if user.id in [u.id for u in doc.who_like] else 'not-favor'
    except:
        return 'not-favor'
